﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Nizm0.QOT.Options
{
    public partial class LocalStorageOption : UserControl, Library.Objects.IOption
    {
        public LocalStorageOption()
        {
            InitializeComponent();

        }

        //private LocalStorage.LocalStorageSettings _storageSettings;

        private string _optionPath = "Main Settings\\Local Storage";
        private string _optionName = "Local Storage";
        private bool _optionChange = true;

        public string OptionPath
        {
            get
            {
                return _optionPath;
            }
            set
            {
                _optionPath = value;
            }
        }

        public string OptionName
        {
            get { return _optionName; }
        }

        public bool OptionChanged
        {
            get { return _optionChange; }
        }

        public bool Save()
        {
            LocalStorage.LocalStorageSettings.Instance.Use = checkBox_LocalStorage.Checked;
            LocalStorage.LocalStorageSettings.Instance.Location = textBox_Location.Text.Trim();
            LocalStorage.LocalStorageSettings.Instance.ServerAdress = textBox_ServerAdress.Text.Trim();
            return LocalStorage.LocalStorageSettings.Instance.Save();
        }

        public new Library.Objects.IOption Show()
        {
            throw new NotImplementedException();
        }

        public void Fill()
        {
            //LocalStorage.LocalStorageSettings.Instance.Load();
            checkBox_LocalStorage.Checked = LocalStorage.LocalStorageSettings.Instance.Use;
            textBox_Location.Text = LocalStorage.LocalStorageSettings.Instance.Location;
            textBox_ServerAdress.Text = LocalStorage.LocalStorageSettings.Instance.ServerAdress;
        }

        private void bt_StorageLocation_Click(object sender, EventArgs e)
        {
            using (Library.FileFolderDialog f = new Library.FileFolderDialog())
            {
                if (DialogResult.OK == f.ShowDialog())
                {
                    textBox_Location.Text = f.SelectedPath;
                }
            }
        }

        private void checkBox_LocalStorage_CheckedChanged(object sender, EventArgs e)
        {
            LocalStorage.LocalStorageSettings.Instance.Use = checkBox_LocalStorage.Checked;
            groupBox1.Enabled = checkBox_LocalStorage.Checked;
        }
    }
}
